package com.learn.project2.controller.admin;

import com.learn.project2.model.bo.admin.issue.IssueCreateBO;
import com.learn.project2.model.bo.admin.issue.IssueDeleteBO;
import com.learn.project2.model.bo.admin.issue.IssueListBO;
import com.learn.project2.model.bo.admin.issue.IssueUpdateBO;
import com.learn.project2.model.vo.admin.issue.IssueCreateVO;
import com.learn.project2.model.vo.admin.issue.IssueListVO;
import com.learn.project2.model.vo.admin.issue.IssueUpdateVO;
import com.learn.project2.service.admin.issue.IssueService;
import com.learn.project2.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * \* Author: Valley
 * \* Date: 2022/1/6
 * \* Time: 22:49
 * \* Description:
 */
@RestController
@RequestMapping("admin/issue")
public class IssueController {

    @Autowired
    IssueService issueService;

    /**
     * @description: 通用问题-查询
     * @param: [listBO]
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-07 19:14:21
     */
    @RequestMapping("list")
    @RequiresPermissions("admin:issue:list")
    public Result list(IssueListBO listBO){
        IssueListVO listVO = issueService.issueList(listBO);
        return Result.ok(listVO);
    }


    /**
     * @description: 通用问题-添加
     * @param: [createBO]
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-07 19:40:52
     */
    @RequestMapping("create")
    @RequiresPermissions("admin:issue:create")
    public Result create(@RequestBody IssueCreateBO createBO){
        IssueCreateVO createVO = issueService.issueCreate(createBO);
        return Result.ok(createVO);
    }


    /**
     * @description: 通用问题-修改
     * @param: [issueUpdateBO]
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-07 19:41:06
     */
    @RequestMapping("update")
    @RequiresPermissions("admin:issue:update")
    public Result update(@RequestBody IssueUpdateBO issueUpdateBO) throws ParseException {
        IssueUpdateVO updateVO = issueService.issueUpdate(issueUpdateBO);
        return Result.ok(updateVO);
    }

    /**
     * @description: 通用问题-删除
     * @param: [deleteBO]
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-07 19:58:09
     */
    @RequestMapping("delete")
    @RequiresPermissions("admin:issue:delete")
    public Result delete(@RequestBody IssueDeleteBO deleteBO){
        Integer code = issueService.issueDelete(deleteBO.getId());
        return Result.ok();
    }

}
